package com.exercise.widgets.switchbar

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import com.exercise.struct.base.BaseActivity
import com.exercise.struct.viewmodel.BaseViewModel
import com.exercise.widgets.databinding.ActivitySwitchBinding
import com.google.android.material.snackbar.Snackbar

class SwitchActivity : BaseActivity<BaseViewModel, ActivitySwitchBinding>() {
    override val bindingInflater: (LayoutInflater) -> ActivitySwitchBinding
        get() = ActivitySwitchBinding::inflate
    override val modelClass: Class<BaseViewModel>
        get() = BaseViewModel::class.java

    override fun initData() {
    }

    override fun initView() {
        binding.materialSwitch.setOnCheckedChangeListener { view, isChecked ->
            Snackbar.make(
                view,
                "$isChecked",
                Snackbar.LENGTH_SHORT
            ).show()
        }
        binding.switchCompat.setOnCheckedChangeListener { view, isChecked ->
            Snackbar.make(
                view,
                "$isChecked",
                Snackbar.LENGTH_SHORT
            ).show()
        }
        binding.toggleButton.setOnCheckedChangeListener { view, isChecked ->
            Snackbar.make(
                view,
                "$isChecked",
                Snackbar.LENGTH_SHORT
            )
                .setText("Title")
                .setAction("Action", null)
                .show()
        }
    }

    companion object {
        fun start(context: Context) {
            Intent(context, SwitchActivity::class.java).also {
                context.startActivity(it)
            }
        }
    }

}